#!/bin/sh

if [ "$CC" = "" ]
then
	echo "Provide CC"
	exit 1
fi

tmpsrc="/tmp/cfggcc.$$.c"
tmpout="/tmp/cfggcc.$$"
tmpopt="/tmp/cfggcc.$$.opt"

trap on_signal 1 2 3 6

on_signal ()
{
	rm -f "$tmpsrc" "$tmpout" "$tmpopt"
	exit 1
}

test_option ()
{
	echo > "$tmpopt"

	count=0
	while [ $# -gt 0 ]
	do
		"$CC" "$1" -o "$tmpout" "$tmpsrc" >/dev/null 2>&1
		if [ $? -eq 0 ]
		then
			echo "$1" >> "$tmpopt"
			count=`expr $count + 1`
		fi
		shift
	done

	if [ $count -eq 0 ]
	then
		return 0
	fi

	for i in `cat $tmpopt`
	do
		echo $i
	done

	echo "Choose an option to use [0 for none]: "
}

#
# main 
#

echo "int main() { return 0; }" > "$tmpsrc"

test_option "-ansi" "-posix" "-traditional" 
test_option "-m32" "-m64"
test_option "-fshort-wchar"

rm -f "$tmpsrc" "$tmpout" "$tmpopt"
exit 0
